package com.iot.mqttbroker.config;


import org.springframework.beans.factory.config.YamlPropertiesFactoryBean;
import org.springframework.core.io.ClassPathResource;

import java.util.Properties;

public abstract class MQTTConfig {


    protected static String broker;

    protected static int qos;
    protected static String port; /* Default port */
    protected static String userName;
    protected static String password;
    protected static String TCP;
    protected static String SSL;

    static {
        YamlPropertiesFactoryBean yamlProFb = new YamlPropertiesFactoryBean();
        yamlProFb.setResources(new ClassPathResource("application.yml"));
        Properties properties = yamlProFb.getObject();
        assert properties != null;
        broker = properties.get("mqtt.broker_url").toString();
        qos = Integer.parseInt(properties.get("mqtt.qos").toString());
        port = properties.get("mqtt.port").toString();
        userName = properties.get("mqtt.username").toString();
        password = properties.get("mqtt.password").toString();
        TCP = properties.get("mqtt.TCP").toString();
        SSL = properties.get("mqtt.SSL").toString();
    }
    /**
     * Custom Configuration
     *
     * @param broker
     * @param port
     * @param ssl
     * @param withUserNamePass
     */
    protected abstract void config(String broker, Integer port, Boolean ssl, Boolean withUserNamePass);

    /**
     * Default Configuration
     */
    protected abstract void config();
}
